﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.CompsitePattern.RoleReward
{
    /// <summary>
    /// 1.递归的编程技巧
    /// 2.递归的应用和组合模式
    /// 3.组合模式：透明和安全
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            double totalMoney = 10000000;//1千万
            //上端只关注1个对象
            AbstractRole role = BuildTree();
            //计算分红
            role.CalculateDividend(totalMoney);

            Console.Read();
        }

        /// <summary>
        /// 构建角色树
        /// 把对象组合起来
        /// </summary>
        /// <returns></returns>
        private static AbstractRole BuildTree()
        {
            AbstractRole role = new Role()
            {
                Name = "能有的年底",
                Percent = 10
            };

            AbstractRole roleCEO = new Role()
            {
                Name = "CEO",
                Percent = 30
            };
            AbstractRole roleAllDepartments = new Role()
            {
                Name = "所有部门共有",
                Percent = 70
            };

            AbstractRole roleImplementDepartment = new Role()
            {
                Name = "实施",
                Percent = 20
            };
            AbstractRole roleTestDepartment = new Role()
            {
                Name = "测试",
                Percent = 10
            };
            AbstractRole roleSaleDepartment = new Role()
            {
                Name = "销售",
                Percent = 30
            };
            AbstractRole roleDevDepartment = new Role()
            {
                Name = "开发",
                Percent = 40
            };
            AbstractRole roleDepartmenManger = new Role()
            {
                Name = "经理",
                Percent = 20
            };
            AbstractRole roleDepartmenHeads = new Role()
            {
                Name = "部门主管",
                Percent = 15
            };
            AbstractRole roleDevTeam = new Role()
            {
                Name = "开发团队",
                Percent = 65
            };
            AbstractRole roleProjectTeam1 = new Role()
            {
                Name = "项目组1",
                Percent = 50
            };
            AbstractRole roleProjectTeam2 = new Role()
            {
                Name = "项目组2",
                Percent = 50
            };
            AbstractRole rolePM = new Role()
            {
                Name = "项目经理",
                Percent = 20
            };
            AbstractRole roleDev = new Role()
            {
                Name = "开发人员",
                Percent = 80
            };
            AbstractRole roleAdvancedDev = new Role()
            {
                Name = "高级开发人员",
                Percent = 40
            };
            AbstractRole roleMiddleDev = new Role()
            {
                Name = "中级开发人员",
                Percent = 30
            };
            AbstractRole rolePrimaryDev = new Role()
            {
                Name = "初级开发人员",
                Percent = 20
            };
            AbstractRole roleShiXiSheng = new Role()
            {
                Name = "实习生",
                Percent = 10
            };
            AbstractRole roleShiXiSheng1 = new Role()
            {
                Name = "实习生1",
                Percent = 25
            };
            AbstractRole roleShiXiSheng2 = new Role()
            {
                Name = "实习生2",
                Percent = 25
            };
            AbstractRole roleShiXiSheng3 = new Role()
            {
                Name = "实习生3",
                Percent = 25
            };
            AbstractRole roleShiXiSheng4 = new Role()
            {
                Name = "实习生4",
                Percent = 25
            };
            //实习生
            roleShiXiSheng.AddChild(roleShiXiSheng1);
            roleShiXiSheng.AddChild(roleShiXiSheng2);
            roleShiXiSheng.AddChild(roleShiXiSheng3);
            roleShiXiSheng.AddChild(roleShiXiSheng4);

            //开发人员
            roleDev.AddChild(roleAdvancedDev);
            roleDev.AddChild(roleMiddleDev);
            roleDev.AddChild(rolePrimaryDev);
            roleDev.AddChild(roleShiXiSheng);

            //项目组2
            roleProjectTeam2.AddChild(rolePM);
            roleProjectTeam2.AddChild(roleDev);

            //开发团队
            roleDevTeam.AddChild(roleProjectTeam1);
            roleDevTeam.AddChild(roleProjectTeam2);

            //开发部门
            roleDevDepartment.AddChild(roleDepartmenManger);
            roleDevDepartment.AddChild(roleDepartmenHeads);
            roleDevDepartment.AddChild(roleDevTeam);

            //所有部门
            roleAllDepartments.AddChild(roleImplementDepartment);//实施部门
            roleAllDepartments.AddChild(roleTestDepartment);//测试部门
            roleAllDepartments.AddChild(roleSaleDepartment);//销售部门
            roleAllDepartments.AddChild(roleDevDepartment);//开发部门

            role.AddChild(roleCEO);
            role.AddChild(roleAllDepartments);

            return role;
        }
    }
}
